package com.roncoo.education.oauth.fiter;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.*;

import org.springframework.stereotype.Component;

@Component
public class CorsFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
    	String url = ((HttpServletRequest) request).getServletPath();
//    	if (url.startsWith("/oauth")) {
//            HttpServletResponse res = (HttpServletResponse) response;
//            res.addHeader("Access-Control-Allow-Credentials", "true");
//            res.addHeader("Access-Control-Allow-Origin", "*");
//            res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
//            res.addHeader("Access-Control-Allow-Headers", "Content-Type,X-CAF-Authorization-Token,sessionToken,X-TOKEN");
//            if (((HttpServletRequest) request).getMethod().equals("OPTIONS")) {
//                response.getWriter().println("ok");
//                return;
//            }	
//    	}
        chain.doFilter(request, response);
    }
    @Override
    public void destroy() {
    }
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }
}
